package com.fzhucc.modules.lesson.repository;

import com.fzhucc.modules.lesson.domain.LessonFirstChapter;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @website https://eladmin.vip
* @author yyg
* @date 2022-12-07
**/
public interface LessonFirstChapterRepository extends JpaRepository<LessonFirstChapter, Integer>, JpaSpecificationExecutor<LessonFirstChapter> {

    @Query("SELECT a from LessonFirstChapter as a where a.lessonId=:lesson_id")
    List<LessonFirstChapter> findByLessonId(int lesson_id);


    /**
     * 根据课程id删除所有一级菜单
     * @param lessonId 课程ID
     */
    @Modifying
    @Query(value = "delete from tb_lesson_first_chapter where lesson_id = ?1",nativeQuery = true)
    void deleteByLessonId(int lessonId);
}